import intro.ex9.*;
/**
 * a tester class for ex9			
 * @author sivandaniel
 *
 */
public class SpaceShipTester {
	private static final int E_TO_ZERO = -200;
	private static final int NUM_OF_SPACESHIPS = 7;
	protected static final int TURNS_PER_SHOOT = 8;
	protected static final int REGAINED_ENERGY = 1;
	private static final int HIT_REDUCTION = 1;
	protected static final int DEFAULT_REG = 1;
	private static final int HEALTH_REDUCTION = 1;
	protected static final int INITIAL_ENERGY = 200;
	private static final int INITIAL_HEALTH = 10;
	protected static final int SHOT_ENERGY = 25;
	protected static final int SHEILD_ENERGY = 3;
    protected static final int TELEPORT_ENERGY = 150;
    protected static final int DONT_TURN = 0;
    protected static final int TURN_LEFT = 1;
    protected static final int TURN_RIGHT = -1;
	private static String[] ships={"a","b","c","f","h","r","s"};
    private static SpaceShip[] testShips=SpaceShipFactory.createSpaceShips(ships);
	
	
		
	
	
	/**
	 * tests the constructor
	 */
	private static void testConstructor(){
		//tests every spaceship
		for(int i=0;i<testShips.length;i++){
			//test if health is set correctly
			if(testShips[i].getHealth()!=INITIAL_HEALTH){
				System.out.println("problem with constructor (health) ship type: "+ships[i]);
			}
			//test if energy is set correctly
			if(testShips[i].getEnergy()!=INITIAL_ENERGY){
				System.out.println("problem with constructor (energy) ship type: "+ships[i]);
			}
			//test if shield is set correctly
			if(testShips[i].getShield()){
				System.out.println("problem with constructor(shield) ship type: "+ships[i]);
			}
		}
	}
	/**
	 * test collidedWithAnotherShip method
	 */
	private static void testCollision(){
		//the health before collision
		int initialHealth;
		//run over all type of ships
		for(int i=0;i<testShips.length;i++){
			//the health before collision
			initialHealth=testShips[i].getHealth();
			//does the collision
			testShips[i].collidedWithAnotherShip();
			int healthAfter = testShips[i].getHealth();
			//checks if the collision reduced health
			if(initialHealth-HEALTH_REDUCTION!=healthAfter)
				System.out.println("probem with collidedWithAnotherShip, shield is off, ship type : "+ships[i]);
			//turns shield on
			testShips[i].turnShieldOn();
			//does the collision
			testShips[i].collidedWithAnotherShip();
			//checks if the collision didn't reduced health
			if(healthAfter!=testShips[i].getHealth())
				System.out.println("probem with collidedWithAnotherShip, shield is on, ship type : "+ships[i]);
			//resets the ship
			testShips[i].reset();
			
		}
	}
	
	private static void testHit(){
		//the health before collision
		int initialHealth;
		//run over all type of ships
		for(int i=0;i<testShips.length;i++){
			//the health before hit
			initialHealth=testShips[i].getHealth();
			//does the Hit
			testShips[i].gotHit();
			int healthAfter = testShips[i].getHealth();
			//checks if the collision reduced health
			if(initialHealth-HEALTH_REDUCTION!=healthAfter)
				System.out.println("probem with gotHit, shield is off, ship type : "+ships[i]);
			//turns shield on
			testShips[i].turnShieldOn();
			//does the collision
			testShips[i].gotHit();
			//checks if the hit didn't reduced health
			if(healthAfter!=testShips[i].getHealth())
				System.out.println("probem with gotHit, shield is on, ship type : "+ships[i]);
			//resets the ship
			testShips[i].reset();
			
		}
	}
	/**
	 * test the teleport 
	 */
	private static void testTeleport(){
		
		int initialEnergy;
		double x,y;
		//run over all types of ships
		for(int i=0;i<testShips.length;i++){
			//the initial energy
			initialEnergy=testShips[i].getEnergy();
			//does the teleport
			testShips[i].teleport();
			//checks if the energy was reduced correctly
			if(testShips[i].getEnergy()!=initialEnergy-TELEPORT_ENERGY)
				System.out.println("probem with teleport, ship type : "+ships[i]);
			//the coordinates of the ship
			x=testShips[i].getPhysics().getX();
			y=testShips[i].getPhysics().getY();
			//Deducts energy to zero  
			testShips[i].setEnergy(E_TO_ZERO);
			testShips[i].teleport();
			//checks if the ship teleports
			if(testShips[i].getPhysics().getX()!=x||testShips[i].getPhysics().getY()!=y){
				System.out.println("probem with teleport, ship type : "+ships[i]);
			}
		}
	}
	
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		testConstructor();
		testTeleport();
		testCollision();
		testHit();

	}

}
